# Calibrates model
if (dem.elasts.to.use=='Base') {
  oil.dem.elast.use = -0.2
  gas.dem.elast.use = -0.2
} else if (dem.elasts.to.use=='High') {
  oil.dem.elast.use = -0.51 # Balke and Brown 2018. Also in line with Metcalf, based on Allaire and Brown 2012 (e=-0.5)
  gas.dem.elast.use = -0.42 # Metcalf, based on Hausman and Kellogg
}

if (prices.to.use=='futures') {
  weo.projections[, brent.base := brent.future]
  weo.projections[, wti.base := wti.future]
  weo.projections[, hh.base := hh.future]
} else if (prices.to.use=='IEA') {
  weo.projections[, brent.base := iea_crude_price]
  weo.projections[, wti.base := iea_crude_price*mean(wti.future/brent.future)]
  weo.projections[, hh.base := gas_price_us]
}

# Update spreads
weo.projections[, gas.spread := (eu_us_gas_spread + china_us_gas_spread)/2]
weo.projections[, gas_price_intl.base := hh.base + gas.spread]

# Adjust US projections to account for missing wells and non-marketed production   
sim.out.global.calibration = excess.demand(p.adj.oil = 1, p.adj.gas=1, 
                                           weo.proj=weo.projections, price.path.dummy=price.path,
                                           base.spuds.adj = base.spuds.adj,
                                           spudregs.use = lm.regs,
                                           oil.dem.elast = oil.dem.elast.use,
                                           gas.dem.elast = gas.dem.elast.use,
                                           Net.Demand.Adjustment = NULL, Demand.Share=0,
                                           US.adjustment.factors = US.adj,
                                           base.prices = weo.projections[,.(date, wti=wti.base, brent=brent.base, hh=hh.base)],
                                           sim.start=sim.start.date, sim.end=sim.end.date, 
                                           global.gas=global.gas.market)


# Find demand adjustment
Net.Demand.Adjustment = sim.out.global.calibration$global.sim[, .(date, Oil.Net.Demand.Adjustment=Excess.Oil.Demand,
                                                                  Gas.Net.Demand.Adjustment=Excess.Gas.Demand)]
